#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include "testutils.h"

void salvager_test()
{
  int i, j, pass, choice, numBuys, tempCard, coin_bonus, coins;
  struct gameState state;

  for(i = 0; i < MAX_ITERATIONS; i++){
    coin_bonus = 0;
    pass = 0;
    init_test_data(&state, 1);

    srand(time(NULL));

    state.deckCount[0] = 50;
    for(j = 0; j < state.deckCount[0]; j++){
      state.deck[0][j] = random_card();
    }
    state.handCount[0] = 5;
    for(j = 0; j < state.handCount[0] - 1; j++){
      state.hand[0][j] = random_card();
    }
    state.hand[0][4] = sea_hag;

    printf("ITERATION %d\n", i);
    
    numBuys = state.numBuys;

    choice = rand() % 4;
    tempCard = state.hand[0][choice];
    // may not want to do a random card so we know the cost without using this function
    coins = getCost(state.hand[0][choice]);

    if(cardEffect(state.hand[0][4], state.hand[0][choice], -1, -1, &state, choice, &coin_bonus) == -1)
      printf("Failure, card effect not returned\n");

    if(state.numBuys == numBuys + 1)
      pass++;
    else
      printf("Failure, player did not gain a buy\n");

    if(state.hand[0][choice] != tempCard)
      pass++;
    else
      printf("Failure, player still has card in hand\n");

    if(state.discard[0][0] != tempCard)
      printf("Failure, player did not have card placed in discard pile\n");
    else
      pass++;

    if(state.coins == coins)
      pass++;
    else
      printf("Failure, player did not gain coins equal to the cost of discarded card\n");
  }
}

int main()
{
  salvager_test();
  return 0;
}
